package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.BaiFocus;
import com.ruoyi.system.service.IBaiFocusService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 焦点图Controller
 * 
 * @author saruri
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/focus")
public class BaiFocusController extends BaseController
{
    @Autowired
    private IBaiFocusService baiFocusService;

    /**
     * 查询焦点图列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BaiFocus baiFocus)
    {
        startPage();
        List<BaiFocus> list = baiFocusService.selectBaiFocusList(baiFocus);
        return getDataTable(list);
    }

    /**
     * 导出焦点图列表
     */
    @RequiresPermissions("system:focus:export")
    @Log(title = "焦点图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaiFocus baiFocus)
    {
        List<BaiFocus> list = baiFocusService.selectBaiFocusList(baiFocus);
        ExcelUtil<BaiFocus> util = new ExcelUtil<BaiFocus>(BaiFocus.class);
        util.exportExcel(response, list, "焦点图数据");
    }

    /**
     * 获取焦点图详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baiFocusService.selectBaiFocusById(id));
    }

    /**
     * 新增焦点图
     */
    @RequiresPermissions("system:focus:add")
    @Log(title = "焦点图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaiFocus baiFocus)
    {
        return toAjax(baiFocusService.insertBaiFocus(baiFocus));
    }

    /**
     * 修改焦点图
     */
    @RequiresPermissions("system:focus:edit")
    @Log(title = "焦点图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaiFocus baiFocus) {
        // 打印传递的数据
        System.out.println("开始打印数据");
        System.out.println("Content: " + baiFocus.getContent()); // HTML 内容
        //System.out.println("Received BaiFocus object: " + baiFocus);

        // 更新焦点图
        return toAjax(baiFocusService.updateBaiFocus(baiFocus));
    }
    /**
     * 删除焦点图
     */
    @RequiresPermissions("system:focus:remove")
    @Log(title = "焦点图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baiFocusService.deleteBaiFocusByIds(ids));
    }
}
